package com.bwie.kafka.consumer;

import com.alibaba.fastjson.JSONObject;
import com.bwie.common.domain.User;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
@Log4j2
public class KafkaConsumer {

    @KafkaListener(topics = "bwie",containerFactory = "kafkaListenerContainerFactory",errorHandler = "myKafkaListenerErrorHandler")
    public void kafkaConsumer(ConsumerRecord<Object,Object> consumerRecord, Acknowledgment acknowledgment){
        User value = (User) consumerRecord.value();
        log.info("接收到消息的内容："+ JSONObject.toJSONString(value));
        acknowledgment.acknowledge();
    }
}
